package com.toe.user.webapi.controller;


import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.user.UserPermissionAddDTO;
import com.toe.pojo.dto.user.UserPermissionUpdateDTO;
import com.toe.pojo.vo.user.UserPermissionVO;
import com.toe.user.service.UserPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/webapi/user-permission")
@Api(tags = "权限模块")
public class UserPermissionController {

    @Autowired
    private UserPermissionService userPermissionService;

    @ApiOperation("添加权限")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody UserPermissionAddDTO userPermissionAddDTO){
        userPermissionService.insert(userPermissionAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除权限")
    @PostMapping("/delete")
    public JsonResult<Void> delete(Long id){
        userPermissionService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询权限")
    @GetMapping("/select")
    public JsonResult<List<UserPermissionVO>> selectAllPermission(){
        List<UserPermissionVO> userPermissionVOS = userPermissionService.selectAllPermission();
        return JsonResult.ok(userPermissionVOS);
    }

    @ApiOperation("分页查询权限")
    @GetMapping("/select/page")
    public JsonResult<JsonPage<UserPermissionVO>> selectAllPermission(Integer pageNum,Integer pageSize){
        JsonPage<UserPermissionVO> userPermissionVOJsonPage = userPermissionService.selectAllPermissionPage(pageNum, pageSize);
        return JsonResult.ok(userPermissionVOJsonPage);
    }

    @ApiOperation("更新权限")
    @PostMapping("/update")
    public JsonResult<Void> updatePermission(@RequestBody UserPermissionUpdateDTO userPermissionUpdateDTO){
        userPermissionService.updatePermission(userPermissionUpdateDTO);
        return JsonResult.ok();
    }
}

